package board;

public class Move implements Comparable{

	float Value;
	Square toSquare=new Square();
	Square fromSquare=new Square();
	char pieceMoved;
	char pieceCaptured;
	
	//The compareTo method returns zero if the object passed is equal to this instance.
	//It returns a positive integer if this object is greater
	//returns negative integer if this object is smaller than the passed object, respectively.
	public int compareTo(Object m){
		
		if (Value > ((Move)m).Value){
			return 1;
		}
		if(Value< ((Move)m).Value){
			return -1;
		}
		else return 0;
	}
	
	public String getMoveAsString(){
		String moveString="";
		switch(fromSquare.GetX()){
		  case 0: moveString+="a";break;
		  case 1: moveString+="b";break;
		  case 2: moveString+="c";break;
		  case 3: moveString+="d";break;
		  case 4: moveString+="e";break;
		}
		switch(fromSquare.GetY()){
		  case 0: moveString+="6";break;
		  case 1: moveString+="5";break;
		  case 2: moveString+="4";break;
		  case 3: moveString+="3";break;
		  case 4: moveString+="2";break;
		  case 5: moveString+="1";break;
		}
		moveString+="-";
		switch(toSquare.GetX()){
		  case 0: moveString+="a";break;
		  case 1: moveString+="b";break;
		  case 2: moveString+="c";break;
		  case 3: moveString+="d";break;
		  case 4: moveString+="e";break;
		}
		switch(toSquare.GetY()){
		  case 0: moveString+="6";break;
		  case 1: moveString+="5";break;
		  case 2: moveString+="4";break;
		  case 3: moveString+="3";break;
		  case 4: moveString+="2";break;
		  case 5: moveString+="1";break;
		}
		return moveString;
	}
	
	public int getPieceMovedAsInt(){
		switch (pieceMoved) {
		  case '.': return 0;
		  case 'p': return 1;
		  case 'k': return 2;
		  case 'q': return 3;
		  case 'b': return 4;
          case 'n': return 5;
          case 'r': return 6;
		  case 'P': return 7;
		  case 'K': return 8;
		  case 'Q': return 9;
		  case 'B': return 10;
		  case 'N': return 11;
		  case 'R': return 12;
		  default: System.out.println("Invalid piece.");
		  			return -1;
		}
	}
	
	public int getPieceCapturedAsInt(){
		switch (pieceCaptured) {
		  case '.': return 0;
		  case 'p': return 1;
		  case 'k': return 2;
		  case 'q': return 3;
		  case 'b': return 4;
          case 'n': return 5;
          case 'r': return 6;
		  case 'P': return 7;
		  case 'K': return 8;
		  case 'Q': return 9;
		  case 'B': return 10;
		  case 'N': return 11;
		  case 'R': return 12;
		  default: System.out.println("Invalid piece.");
		  			return -1;
		}
	}
	
	public int getToSquareAsBitBoardInt(){
		return toSquare.GetX()*6+toSquare.GetY();
	}
	public int getFromSquareAsBitBoardInt(){
		return fromSquare.GetX()*6+fromSquare.GetY();
	}
}
